home *** CD-ROM | disk | FTP | other *** search
/ United Public Domain Gold 2 / United Public Domain Gold 2.iso / utilities / pu374.dms / pu374.adf / Plasma / Plasma_256.c < prev    next >
C/C++ Source or Header  |  1992-12-06  |  19KB  |  745 lines

  1. /*************************************************
  2. /*
  3. /* Plasma Cloud Generator 256 Color Version
  4. /* AGA only (a4000/A1200 et al) uses 320X400 or 640X400
  5. /* for HIRES run from CLI and type Plasma_256 HIRES
  6. /* if run with no args, or from WB it will be lo-res
  7. /* 256 color displays with 24 bit palette.
  8. /* This code © 1992 by W. Roger uzun
  9. /* This code is for SAS/C 6.0x
  10. /* First assemble FastPix.asm by using SAS/C asm
  11. /* use smallcode and smalldata for models
  12. /* To Color Cycle Press C, press space to quit color cycle
  13. /* and restore palette to original, any other key keeps
  14. /* current palette.
  15. /*
  16. /*************************************************/
  17.  
  18. #define FASTER 1
  19.  
  20. long __OSlibversion = 39;
  21.  
  22. #define HEIGHT 400L
  23. #define DEPTH 8
  24. int WIDTH=320L;
  25. #define VIEW_MODES (LACE)
  26. #define NUM_COLORS 256
  27. #define CPU020 1
  28. #include <stdio.h>
  29. #include <stdlib.h>
  30. #include <string.h>
  31. #include <math.h>
  32. #include <proto/exec.h>
  33. #ifdef CPU020
  34. #include <exec/execbase.h>
  35. #endif
  36. #include <proto/intuition.h>
  37. #include <proto/graphics.h>
  38. #include <time.h>
  39. #include <proto/dos.h>
  40. int rowoffset=(320L/8);
  41. #define MODULUS (0x20000L)
  42. #define C 13849
  43. #define A 25173
  44. #define randu2(x) (((seed = seed*A+C))%(x))
  45. #ifdef LATTICE
  46. #define PROTOTYPES 1
  47. #endif
  48.  
  49. #ifndef LATTICE
  50. #define __regargs
  51. #endif
  52.  
  53. #ifdef DEBUG
  54. int temparray[64];
  55. #endif
  56.  
  57. #define WINDOWSIGNAL (1L<<(wG->UserPort->mp_SigBit))
  58.  
  59. #define PaletteColorCount 32
  60.  
  61. short __aligned nplanes = DEPTH;
  62. UBYTE __aligned *bp[DEPTH];
  63. short __aligned ytable[HEIGHT];
  64.  
  65. struct TextFont __aligned *myTextFont;
  66.  
  67. struct RastPort __aligned *rpG;
  68.  
  69. struct TextAttr TOPAZ80 = {
  70.     (STRPTR)"topaz.font",
  71.     TOPAZ_EIGHTY,0,0
  72. };
  73. struct NewScreen NewScreenStructure = {
  74.     0,0,    /* screen XY origin relative to View */
  75.     320L,HEIGHT,    /* screen width and height */
  76.     DEPTH,    /* screen depth (number of bitplanes) */
  77.     0,1,    /* detail and block pens */
  78.     VIEW_MODES,    /* display modes for this screen */
  79.     CUSTOMSCREEN,    /* screen type */
  80.     &TOPAZ80,    /* pointer to default screen font */
  81.     "Plasma 256",    /* screen title */
  82.     NULL,    /* first in list of custom screen gadgets */
  83.     NULL    /* pointer to custom BitMap structure */
  84. };
  85.  
  86. #define NEWSCREENSTRUCTURE NewScreenStructure
  87.  
  88.  
  89. struct PalletteEntry {
  90. ULONG red,green,blue;
  91. };
  92.  
  93. struct PalletteEntry Red = {0xff,0,0};
  94. struct PalletteEntry Green = {0,0xff,0};
  95. struct PalletteEntry Blue = {0,0,0xff};
  96.  
  97.  
  98. #define SCALE8TO32(x) ((x)|((x)<<8)|((x)<<16)|((x)<<24))
  99.  
  100. ULONG BigColorPalette[256*3+2]={256<<16 /* this says load 256 colors */ + 
  101.                            0, /* start at color register 0 */
  102.                            0x0, /* red for color 0 */
  103.                            0x0, /* green for color 0 */
  104.                            0x0, /* blue for color 0, color 0 is Black */
  105.                            0xffffffff,
  106.                            0xffffffff,
  107.                            0xffffffff /* color 1 is white */
  108.                            };
  109.  
  110. USHORT __aligned Palette[] = {
  111.     0x000,    /* color #0 */
  112.     0x0a5,  /* color #6 */
  113.     0x0b4,  /* color #7 */
  114.     0x0c3,  /* color #8 */
  115.     0x0e1,  /* color #9 */
  116.     0x0f0,  /* color #10 */
  117.  
  118.     0x01f0,    /* color #11 */
  119.     0x03d0,    /* color #12 */
  120.     0x05b0,    /* color #13 */
  121.     0x0790,    /* color #14 */
  122.     0x0970,    /* color #15 */
  123.     0x0a50,    /* color #16 */
  124.     0x0B40,    /* color #17 */
  125.     0x0c30,    /* color #18 */
  126.     0x0e10,    /* color #19 */
  127.     0x0f00,    /* color #20 */
  128.  
  129.     0x0f01,    /* color #21 */
  130.     0x0d03,    /* color #22 */
  131.     0x0b05,    /* color #23 */
  132.     0x0907,    /* color #24 */
  133.     0x0709,    /* color #25 */
  134.     0x050a,    /* color #26 */
  135.     0x040b,    /* color #27 */
  136.     0x030c,    /* color #28 */
  137.     0x020d,    /* color #29 */
  138.     0x010e,    /* color #30 */
  139.     0x000f,  /* color #31 */
  140.     0x01f,    /* color #1 */
  141.     0x03d,    /* color #2 */
  142.     0x05b,    /* color #3 */
  143.     0x079,    /* color #4 */
  144.     0x097    /* color #5 */
  145. };
  146.  
  147. #define PALETTE Palette
  148.  
  149. struct IntuiText IText1 = {
  150.     3,1,JAM1,    /* front and back text pens, drawmode and fill byte */
  151.     0,0,    /* XY origin relative to container TopLeft */
  152.     &TOPAZ80,    /* font pointer or NULL for default */
  153.     "Quit",    /* pointer to text */
  154.     NULL    /* next IntuiText structure */
  155. };
  156.  
  157. struct MenuItem MenuItem2 = {
  158.     NULL,    /* next MenuItem structure */
  159.     0,8,    /* XY of Item hitbox relative to TopLeft of parent hitbox */
  160.     80,8,    /* hit box width and height */
  161.     ITEMTEXT+COMMSEQ+ITEMENABLED+HIGHCOMP,    /* Item flags */
  162.     0,    /* each bit mutually-excludes a same-level Item */
  163.     (APTR)&IText1,    /* Item render  (IntuiText or Image or NULL) */
  164.     NULL,    /* Select render */
  165.     'Q',    /* alternate command-key */
  166.     NULL,    /* SubItem list */
  167.     MENUNULL    /* filled in by Intuition for drag selections */
  168. };
  169.  
  170. struct IntuiText IText2 = {
  171.     3,1,JAM1,    /* front and back text pens, drawmode and fill byte */
  172.     0,0,    /* XY origin relative to container TopLeft */
  173.     &TOPAZ80,    /* font pointer or NULL for default */
  174.     "About",    /* pointer to text */
  175.     NULL    /* next IntuiText structure */
  176. };
  177.  
  178. struct MenuItem MenuItem1 = {
  179.     &MenuItem2,    /* next MenuItem structure */
  180.     0,0,    /* XY of Item hitbox relative to TopLeft of parent hitbox */
  181.     80,8,    /* hit box width and height */
  182.     ITEMTEXT+COMMSEQ+ITEMENABLED+HIGHCOMP,    /* Item flags */
  183.     0,    /* each bit mutually-excludes a same-level Item */
  184.     (APTR)&IText2,    /* Item render  (IntuiText or Image or NULL) */
  185.     NULL,    /* Select render */
  186.     'A',    /* alternate command-key */
  187.     NULL,    /* SubItem list */
  188.     MENUNULL    /* filled in by Intuition for drag selections */
  189. };
  190.  
  191. struct Menu Menu1 = {
  192.     NULL,    /* next Menu structure */
  193.     0,0,    /* XY origin of Menu hit box relative to screen TopLeft */
  194.     63,0,    /* Menu hit box width and height */
  195.     MENUENABLED,    /* Menu flags */
  196.     "Project",    /* text of Menu name */
  197.     &MenuItem1    /* MenuItem linked list pointer */
  198. };
  199.  
  200. #define MenuList1 Menu1
  201.  
  202. struct NewWindow NewWindowStructure1 = {
  203.     0,0,    /* window XY origin relative to TopLeft of screen */
  204.     320L,HEIGHT,    /* window width and height */
  205.     4,8,    /* detail and block pens */
  206.     VANILLAKEY|MENUPICK,    /* IDCMP flags */
  207.     SMART_REFRESH+BACKDROP+BORDERLESS+ACTIVATE,    /* other window flags */
  208.     NULL,    /* first gadget in gadget list */
  209.     NULL,    /* custom CHECKMARK imagery */
  210.     " ",    /* window title */
  211.     NULL,    /* custom screen pointer */
  212.     NULL,    /* custom bitmap */
  213.     5,5,    /* minimum width and height */
  214.     0xffff,0xffff,    /* maximum width and height */
  215.     CUSTOMSCREEN    /* destination screen type */
  216. };
  217.  
  218. SHORT BorderVectors1[] = {
  219.     0,0,
  220.     51,0,
  221.     51,41,
  222.     0,41,
  223.     0,0
  224. };
  225. struct Border Border1 = {
  226.     -1,-1,    /* XY origin relative to container TopLeft */
  227.     3,0,JAM1,    /* front pen, back pen and drawmode */
  228.     5,    /* number of XY vectors */
  229.     BorderVectors1,    /* pointer to XY vectors */
  230.     NULL    /* next border in list */
  231. };
  232.  
  233. struct IntuiText IText3 = {
  234.     3,0,JAM2,    /* front and back text pens, drawmode and fill byte */
  235.     15,17,    /* XY origin relative to container TopLeft */
  236.     NULL,    /* font pointer or NULL for default */
  237.     "OK",    /* pointer to text */
  238.     NULL    /* next IntuiText structure */
  239. };
  240.  
  241. struct Gadget Gadget1 = {
  242.     NULL,    /* next gadget */
  243.     65,217,    /* origin XY of hit box relative to window TopLeft */
  244.     50,40,    /* hit box width and height */
  245.     NULL,    /* gadget flags */
  246.     RELVERIFY,    /* activation flags */
  247.     BOOLGADGET,    /* gadget type flags */
  248.     (APTR)&Border1,    /* gadget border or image to be rendered */
  249.     NULL,    /* alternate imagery for selection */
  250.     &IText3,    /* first IntuiText structure */
  251.     NULL,    /* gadget mutual-exclude long word */
  252.     NULL,    /* SpecialInfo structure */
  253.     NULL,    /* user-definable data */
  254.     NULL    /* pointer to user-definable data */
  255. };
  256.  
  257. #define GadgetList2 Gadget1
  258.  
  259. struct IntuiText IText5 = {
  260.     3,0,JAM2,    /* front and back text pens, drawmode and fill byte */
  261.     40,114,    /* XY origin relative to container TopLeft */
  262.     NULL,    /* font pointer or NULL for default */
  263.     "By Roger Uzun",    /* pointer to text */
  264.     NULL    /* next IntuiText structure */
  265. };
  266.  
  267. struct IntuiText IText4a = {
  268.     3,0,JAM2,    /* front and back text pens, drawmode and fill byte */
  269.     16,61,    /* XY origin relative to container TopLeft */
  270.     NULL,    /* font pointer or NULL for default */
  271.     "Press 'C' to Cycle",    /* pointer to text */
  272.     &IText5    /* next IntuiText structure */
  273. };
  274.  
  275. #ifndef CPU020
  276. struct IntuiText IText4 = {
  277.     3,0,JAM2,    /* front and back text pens, drawmode and fill byte */
  278.     6,21,    /* XY origin relative to container TopLeft */
  279.     NULL,    /* font pointer or NULL for default */
  280.     "Plasma 256 Ver 0.0",    /* pointer to text */
  281.     &IText4a    /* next IntuiText structure */
  282. };
  283. #else
  284. struct IntuiText IText4c = {
  285.     3,0,JAM2,    /* front and back text pens, drawmode and fill byte */
  286.     35,41,    /* XY origin relative to container TopLeft */
  287.     NULL,    /* font pointer or NULL for default */
  288.     "68020 Edition",    /* pointer to text */
  289.     &IText4a    /* next IntuiText structure */
  290. };
  291. struct IntuiText IText4 = {
  292.     3,0,JAM2,    /* front and back text pens, drawmode and fill byte */
  293.     6,21,    /* XY origin relative to container TopLeft */
  294.     NULL,    /* font pointer or NULL for default */
  295.     "Plasma 256 Ver 0.0",    /* pointer to text */
  296.     &IText4c    /* next IntuiText structure */
  297. };
  298. #endif
  299.  
  300. struct NewWindow NewWindowStructure3 = {
  301.     70,30,    /* window XY origin relative to TopLeft of screen */
  302.     180,280,    /* window width and height */
  303.     0,1,    /* detail and block pens */
  304.     GADGETUP,    /* IDCMP flags */
  305.     SIMPLE_REFRESH+ACTIVATE+NOCAREREFRESH,    /* other window flags */
  306.     &Gadget1,    /* first gadget in gadget list */
  307.     NULL,    /* custom CHECKMARK imagery */
  308.     " ",    /* window title */
  309.     NULL,    /* custom screen pointer */
  310.     NULL,    /* custom bitmap */
  311.     5,5,    /* minimum width and height */
  312.     0xffff,0xffff,    /* maximum width and height */
  313.     CUSTOMSCREEN    /* destination screen type */
  314. };
  315.  
  316.  
  317. struct Screen __aligned *sC;
  318. struct Window __aligned *wG;
  319. UWORD __aligned done=0;
  320.  
  321. unsigned short __aligned seed = 7;
  322.  
  323. #ifdef PROTOTYPES
  324.  
  325.  
  326. #ifdef FASTER
  327. int __regargs ReadPix(long,long);
  328. void __regargs FastPix(long,long,long);
  329. #endif
  330.  
  331. void CycleColors(void);
  332. void __regargs HandleEvent(APTR);
  333. void DoAbout(void);
  334. void DoQuit(void);
  335. void __regargs SubDivide(long,long,long,long);
  336. void __regargs adjust(long,long,long,long,long,long);
  337.  
  338. #endif
  339.  
  340.  
  341. ULONG tpal[256*3+2];
  342.  
  343. void CycleColors()
  344. {
  345.  long __aligned code;
  346.  ULONG __aligned class;
  347.  UWORD __aligned d=0,i;
  348.  ULONG temp[3];
  349.  struct IntuiMessage __aligned *message;
  350.  
  351.  for(i=0;i<(256*3+2);i++)
  352.   {
  353.    tpal[i] = BigColorPalette[i];
  354.   }
  355.  while (!d)
  356.   {
  357.    temp[0] = tpal[4];
  358.    temp[1] = tpal[5];
  359.    temp[2] = tpal[6];
  360.    for(i=2;i<256;i++)
  361.     {
  362.      tpal[(i-1)*3+1] = tpal[i*3+1];
  363.      tpal[(i-1)*3+2] = tpal[i*3+2];
  364.      tpal[(i-1)*3+3] = tpal[i*3+3];
  365.     }
  366.    tpal[255*3] = temp[0];
  367.    tpal[255*3+1] = temp[1];
  368.    tpal[255*3+2] = temp[2];
  369.    LoadRGB32(&(sC->ViewPort),tpal);
  370.    Delay(1L);
  371.    if ( (message = (struct IntuiMessage *)
  372.     GetMsg(wG->UserPort) ))
  373.     {
  374.     class = message->Class;
  375.     code = message->Code;
  376.     ReplyMsg((struct Message *)message);
  377.     if (class = VANILLAKEY)
  378.      d = 1;
  379.     }
  380.   }
  381.  if (code == ' ')
  382.   LoadRGB32(&(sC->ViewPort),BigColorPalette);
  383. }
  384.  
  385. void __regargs adjust(xa,ya,x,y,xb,yb)
  386. long xa,ya,x,y,xb,yb;
  387. {
  388.  long __aligned t1,t2;
  389.  int __aligned pa,pb,pc,pd;
  390.  register long __aligned globalcolor;
  391.  
  392. #ifdef FASTER
  393.  if (ReadPix(x,y))
  394.   return;
  395. #else
  396.  if (ReadPixel(rpG,x,y))
  397.   return;
  398. #endif
  399.  pa = xa;
  400.  pb  =xb;
  401.  pc = ya;
  402.  pd = yb;
  403.  globalcolor = randu2(3) * (abs(pa-pb)+abs(pc-pd));
  404. #ifdef FASTER
  405.  t1 = (ReadPix(xa,ya));
  406.  t2 = (ReadPix(xb,yb));
  407. #else
  408.  t1 = (ReadPixel(rpG,xa,ya));
  409.  t2 = (ReadPixel(rpG,xb,yb));
  410. #endif
  411.  if (!randu2(2))
  412.   {
  413.    globalcolor = -globalcolor;
  414.   }
  415.  globalcolor = ((t1+t2)>>1)+globalcolor;
  416.  globalcolor &= 0xffL;
  417. #ifdef FASTER
  418.  FastPix(x,y,globalcolor);
  419. #else
  420.  SetAPen(rpG,globalcolor);
  421.  WritePixel(rpG,x,y);
  422. #endif
  423. #ifdef DEBUG
  424. temparray[globalcolor]++;
  425. #endif
  426. }
  427.  
  428. void __regargs SubDivide(x1,y1,x2,y2)
  429. long x1,y1,x2,y2;
  430. {
  431.  long __aligned t1,t2,t3,t4;
  432.  ULONG __aligned signals,v;
  433.  struct IntuiMessage __aligned *message;
  434.  long __aligned x,y,class,code;
  435.  APTR __aligned object;
  436.  UWORD __aligned d;
  437.  
  438.  if (((x2-x1)<2L) && ((y2-y1)<2L))
  439.   return;
  440.  if ( (message = (struct IntuiMessage *)
  441.     GetMsg(wG->UserPort) ))
  442.   {
  443.     class = message->Class;
  444.     code = message->Code;
  445.     object = message->IAddress;  /* Gadget */
  446.     ReplyMsg((struct Message *)message);
  447.     if ( class == MENUPICK )    /* MenuItems */
  448.      HandleEvent((APTR)ItemAddress(&MenuList1,code));
  449.     else if (class = VANILLAKEY)
  450.      {
  451.           if ((code == 'c')||(code == 'C'))
  452.        {
  453.         CycleColors();
  454.        }
  455.           else
  456.            {
  457.         d = 0;
  458.         while(!d)
  459.          {
  460.           signals = Wait(WINDOWSIGNAL);
  461.           if (signals & WINDOWSIGNAL)
  462.            while ((message = (struct IntuiMessage *)
  463.                   GetMsg(wG->UserPort)))
  464.             {
  465.              class = message->Class;
  466.              ReplyMsg((struct Message *)message);
  467.              if (class == VANILLAKEY)
  468.               d = 1;
  469.             }
  470.          }
  471.            }
  472.      }
  473.   }
  474.  if (done)
  475.   return;
  476.  x = (x1+x2)>>1;
  477.  y = (y1+y2)>>1;
  478. #ifdef FASTER
  479.  if (!ReadPix(x,y))
  480.   {
  481.    t1 = (ReadPix(x1,y1));
  482.    t2 = (ReadPix(x2,y1));
  483.    t3 = (ReadPix(x2,y2));
  484.    t4 = (ReadPix(x1,y2));
  485. #else
  486.  if (!ReadPixel(rpG,x,y))
  487.   {
  488.    t1 = (ReadPixel(rpG,x1,y1));
  489.    t2 = (ReadPixel(rpG,x2,y1));
  490.    t3 = (ReadPixel(rpG,x2,y2));
  491.    t4 = (ReadPixel(rpG,x1,y2));
  492. #endif
  493.    v = ((t1+t2+t3+t4)>>2);
  494. #ifdef FASTER
  495.  FastPix(x,y,v);
  496. #else
  497.  SetAPen(rpG,v);
  498.  WritePixel(rpG,x,y);
  499. #endif
  500.   }
  501.  adjust(x1,y1,x,y1,x2,y1);
  502.  adjust(x2,y1,x2,y,x2,y2);
  503.  adjust(x1,y2,x,y2,x2,y2);
  504.  adjust(x1,y1,x1,y,x1,y2);
  505.  SubDivide(x1,y1,x,y);
  506.  SubDivide(x,y1,x2,y);
  507.  SubDivide(x,y,x2,y2);
  508.  SubDivide(x1,y,x,y2);
  509. }
  510.  
  511. void DoAbout()
  512. {
  513.  struct IntuiMessage __aligned *message;
  514.  struct Window __aligned *wG3;
  515.  
  516.  if (!(wG3 = OpenWindow(&NewWindowStructure3)))
  517.  {
  518.   DisplayBeep(0L);
  519.   return;
  520.  }
  521.  PrintIText(wG3->RPort,&IText4,0L,0L);
  522.  WaitPort(wG3->UserPort);
  523.  while(message = (struct IntuiMessage *)GetMsg(wG3->UserPort))
  524.   ReplyMsg((struct Message *)message);
  525.  CloseWindow(wG3);
  526. }
  527.  
  528. void __regargs HandleEvent(object)
  529. APTR object;
  530. {
  531.   if (object == (APTR)&MenuItem1) { DoAbout(); return; }
  532.   if (object == (APTR)&MenuItem2) { DoQuit(); return; }
  533. }
  534. #define HANDLEEVENT HandleEvent
  535.  
  536. /* end of PowerWindows source generation */
  537.  
  538.  
  539.  
  540. void DoQuit()
  541. {
  542.  done = TRUE;
  543. }
  544.  
  545. /* end of PowerWindows source generation */
  546.  
  547.  
  548. void main(int,char **);
  549. void main(argc,argv)
  550. int argc;
  551. char *argv[];
  552. {
  553.  int __aligned j;
  554.  int __aligned i;
  555. #ifdef DEBUG
  556. int __aligned d;
  557. #endif
  558.     ULONG __aligned code;
  559.     ULONG __aligned class;
  560.     APTR __aligned object;
  561.     ULONG __aligned signals;
  562.     struct IntuiMessage __aligned *message;    /* the message the IDCMP sends us */
  563.  
  564. #ifdef CPU020
  565.  
  566.  struct ExecBase **execbaseptr=(struct ExecBase **)4L;
  567.  UWORD cpuid;
  568.  struct ExecBase *execbase;
  569.  
  570.  if (argc > 1)
  571.   { /* hires */
  572.    NewScreenStructure.Width = 640;
  573.    NewScreenStructure.ViewModes = LACE|HIRES;
  574.    WIDTH = 640;
  575.    NewWindowStructure1.Width = 640;
  576.   }
  577.  execbase = *execbaseptr;
  578.  cpuid = execbase->AttnFlags;
  579.  if (!(cpuid & AFF_68020))
  580.   {
  581.    exit(0);
  582.   }
  583. #endif
  584.  
  585. rowoffset=(WIDTH/8);
  586.  
  587. nplanes = DEPTH - 1;
  588.  
  589. /* We want Blues, Greens then reds in our palette */
  590. for(i=1,j=4;i<85;i++,j+=3)
  591.   {
  592.    BigColorPalette[j] = (i*Green.red + (86-i)*Blue.red)/85;
  593.    BigColorPalette[j+1] = (i*Green.green+ (86-i)*Blue.green)/85;
  594.    BigColorPalette[j+2] = (i*Green.blue + (86-i)*Blue.blue)/85;
  595.  
  596.    BigColorPalette[j+85*3] = (i*Red.red + (86-i)*Green.red)/85;
  597.    BigColorPalette[j+85*3+1] = (i*Red.green+ (86-i)*Green.green)/85;
  598.    BigColorPalette[j+85*3+2] = (i*Red.blue + (86-i)*Green.blue)/85;
  599.  
  600.    BigColorPalette[j+170*3] = (i*Blue.red + (86-i)*Red.red)/85;
  601.    BigColorPalette[j+170*3+1] = (i*Blue.green+ (86-i)*Red.green)/85;
  602.    BigColorPalette[j+170*3+2] = (i*Blue.blue + (86-i)*Red.blue)/85;
  603.   }
  604. BigColorPalette[85*3+1] = 0;
  605. BigColorPalette[85*3+2] = 0xff;
  606. BigColorPalette[85*3+3] = 3;
  607. BigColorPalette[170*3+1] = 0xff;
  608. BigColorPalette[170*3+2] = 0x3;
  609. BigColorPalette[170*3+3] = 0;
  610. BigColorPalette[255*3+1] = 3;
  611. BigColorPalette[255*3+2] = 0x0;
  612. BigColorPalette[255*3+3] = 0xff;
  613. BigColorPalette[256*3+1] = 0L;
  614. BigColorPalette[256*3+1] = 0L;
  615. for(j=4;j<256*3+1;j++)
  616.   BigColorPalette[j] = SCALE8TO32(BigColorPalette[j]);
  617. #ifdef DEBUG
  618. for(d=0;d<64;d++)temparray[d] = 0;
  619. #endif
  620. #ifdef OLD_COMPILER
  621.     if(!(IntuitionBase = (struct IntuitionBase *)OpenLibrary("intuition.library", 33L)))
  622.          {
  623.            exit(0);
  624.          }
  625.     if(!(GfxBase = (struct GfxBase *)OpenLibrary("graphics.library", 33L)))
  626.          {
  627. #ifdef OLD_COMPILER
  628.            CloseLibrary((struct Library *)IntuitionBase);
  629. #endif
  630.            exit(0);
  631.          }
  632. #endif
  633.         if (!(myTextFont = OpenFont(&TOPAZ80)))
  634.          {
  635. #ifdef OLD_COMPILER
  636.           CloseLibrary((struct Library *)GfxBase);
  637.           CloseLibrary((struct Library *)IntuitionBase);
  638. #endif
  639.           exit(0);
  640.          }
  641.     if (!(sC = OpenScreen(&NewScreenStructure)))
  642.          {
  643.           CloseFont(myTextFont);
  644. #ifdef OLD_COMPILER
  645.           CloseLibrary((struct Library *)GfxBase);
  646.           CloseLibrary((struct Library *)IntuitionBase);
  647. #endif
  648.           exit(0);
  649.          }
  650.     LoadRGB32(&(sC->ViewPort),BigColorPalette);
  651.     NewWindowStructure3.Screen = NewWindowStructure1.Screen = sC;
  652.     wG = OpenWindow(&NewWindowStructure1);    /* open the window */
  653.     if ( wG == NULL )
  654.     {
  655.       CloseScreen(sC);
  656.           CloseFont(myTextFont);
  657. #ifdef OLD_COMPILER
  658.           CloseLibrary((struct Library *)GfxBase);
  659.           CloseLibrary((struct Library *)IntuitionBase);
  660. #endif
  661.           exit(0);
  662.     }
  663.     rpG = wG->RPort;    /* get a rastport pointer for the window */
  664.     SetFont(rpG,myTextFont);
  665.     SetMenuStrip(wG,&MenuList1);    /* attach any Menu */
  666.         SetDrMd(rpG,JAM1);
  667.         for(i=0;i<DEPTH;i++)
  668.          bp[i] = wG->RPort->BitMap->Planes[i];
  669.         ytable[0] = 0;
  670.     for(i=1;i<HEIGHT;i++)
  671.      ytable[i] = ytable[i-1] + rowoffset;
  672. #ifdef COLOR_DEBUG
  673. for(i=0;i<256;i++)
  674.  {
  675.   SetAPen(rpG,i);
  676.   RectFill(rpG,30L,30L,60L,60L);
  677.   Delay(5L);
  678.  }
  679. #endif
  680.  
  681.         seed = time(0L);
  682.         signals = (randu2((NUM_COLORS-1))) + 1L;
  683. #ifdef FASTER
  684.  FastPix(0L,11L,signals);
  685. #else
  686.  SetAPen(rpG,signals);
  687.  WritePixel(rpG,0L,11L);
  688. #endif
  689.         signals = (randu2((NUM_COLORS-1))) + 1L;
  690. #ifdef FASTER
  691.  FastPix(WIDTH-1,11L,signals);
  692. #else
  693.  SetAPen(rpG,signals);
  694.  WritePixel(rpG,WIDTH-1,11L);
  695. #endif
  696.         signals = (randu2((NUM_COLORS-1))) + 1L;
  697. #ifdef FASTER
  698.  FastPix(WIDTH-1,HEIGHT-1L,signals);
  699. #else
  700.  SetAPen(rpG,signals);
  701.  WritePixel(rpG,WIDTH-1,HEIGHT-1L);
  702. #endif
  703.         signals = (randu2((NUM_COLORS-1))) + 1L;
  704. #ifdef FASTER
  705.  FastPix(0L,HEIGHT-1L,signals);
  706. #else
  707.  SetAPen(rpG,signals);
  708.  WritePixel(rpG,0L,HEIGHT-1L);
  709. #endif
  710.         SubDivide(0L,11L,WIDTH-1L,HEIGHT-1L);
  711.     DisplayBeep(0L);
  712.     while(!done)
  713.     {
  714.         signals = Wait(WINDOWSIGNAL);
  715.         if (signals & WINDOWSIGNAL)
  716.             while( (message = (struct IntuiMessage *)
  717.                 GetMsg(wG->UserPort) ) != NULL)
  718.             {
  719.                 class = message->Class;
  720.                 code = message->Code;
  721.                 object = message->IAddress;  /* Gadget */
  722.                 ReplyMsg((struct Message *)message);
  723.                 if ( class == MENUPICK )    /* MenuItems */
  724.                  HandleEvent((APTR)ItemAddress(&MenuList1,code));
  725.                 else if (class = VANILLAKEY)
  726.                  {
  727.                       if ((code == 'c')||(code == 'C'))
  728.                    {
  729.                     CycleColors();
  730.                    }
  731.                  }
  732.             }
  733.     }
  734.         CloseWindow(wG);
  735.         CloseFont(myTextFont);
  736.         CloseScreen(sC);
  737. #ifdef OLD_COMPILER
  738.         CloseLibrary((struct Library *)GfxBase);
  739.         CloseLibrary((struct Library *)IntuitionBase);
  740. #endif
  741. #ifdef DEBUG
  742. for(d=0;d<64;d++)printf("temp[%d] = %d\n",d,temparray[d]);
  743. #endif
  744. }
  745.